/*
 * @Author: wangxiaojie
 * @LastEditors: wangxiaojie
 */
function createStore (reducer, preloadedState) {
  let currentReducer = reducer
  let currentState = preloadedState
  let effection
  return {
    getState() {
      return currentState
    },

    dispatch(action) {
      currentState = currentReducer(currentState, action)
      effection()
    },

    effect(fn) {
      effection = fn
    }
  }
}

module.exports = {
  createStore
}